// 请求病毒信息
import {reactive,onMounted} from 'vue'
import api from '../api/index'

export default function() {
    // 存储病毒信息
    let point = reactive({
        // 病毒信息简介
        note1: '',
        note2: '',
        note3: '',
        // 新闻热点
        remark1: '',
        remark2: '',
        remark3: '',
        news: [],
        // 风险地区
        riskarea: {
            high: [],
            mid: []
        },
        // 更新时间
        // modifyTime: 0,
        // 国内数据 & 相比昨日
        homeData: {
            // 现存确诊
            nowSurvive: {
                name: '现存确诊',  // 数据名称
                count: '',  // 详细数据
                incr: ''   // 增量（相比昨日）
            },
            // 境外输入
            abroad: {
                name: '境外输入',
                count: '',
                incr: ''
            },
            // 现存无症状
            noSymptoms: {
                name: '现存无症状',
                count: '',
                incr: ''
            },
            // 累计确诊
            allSurvive: {
                name: '累计确诊',
                count: '',
                incr: ''
            },
            // 累计死亡
            allDie: {
                name: '累计死亡',
                count: '',
                incr: ''
            },
            // 累计治愈
            allCure: {
                name: '累计治愈',
                count: '',
                incr: '',
            }
        }
    })

    onMounted(()=>{
        // 请求病毒接口
        api.getCovInfo().then(res => {
            console.log(res.data.newslist[0]);
            let data = res.data.newslist[0].desc;
            // 病毒信息的介绍数据
            point.note1 = data.note1
            point.note2 = data.note2
            point.note3 = data.note3
            point.remark1 = data.remark1
            point.remark2 = data.remark2
            point.remark3 = data.remark3
            // 疫情热点
            point.news = res.data.newslist[0].news
            // 国内数据
            point.homeData.nowSurvive.count = data.currentConfirmedCount
            point.homeData.nowSurvive.incr = data.currentConfirmedIncr
            point.homeData.abroad.count = data.suspectedCount
            point.homeData.abroad.incr = data.suspectedIncr
            point.homeData.noSymptoms.count = data.seriousCount
            point.homeData.noSymptoms.incr = data.seriousIncr
            point.homeData.allSurvive.count = data.confirmedCount
            point.homeData.allSurvive.incr = data.confirmedIncr
            point.homeData.allDie.count = data.deadCount
            point.homeData.allDie.incr = data.deadIncr
            point.homeData.allCure.count = data.curedCount
            point.homeData.allCure.incr = data.curedIncr
            // 地区风险
            point.riskarea.high = res.data.newslist[0].riskarea.high
            point.riskarea.mid = res.data.newslist[0].riskarea.mid
            // 获取更新时间
            point.modifyTime = new Date(data.modifyTime).toLocaleString("chinese", {hour12: true}).replace(/\//g, "-")
        })
    })
    

    return point
}